package com.hsy.crm.web.web;

import com.hsy.crm.web.domain.cm.Response;
import com.hsy.crm.web.domain.cm.SecretKey;
import com.hsy.crm.web.domain.cm.Unified;
import com.hsy.crm.web.domain.entity.Order;
import com.hsy.crm.web.domain.po.order.OrderRefreshPo;
import com.hsy.crm.web.domain.vo.order.BatchPageVo;
import com.hsy.crm.web.domain.vo.order.OrderGetVo;
import com.hsy.crm.web.domain.vo.order.OrderPageVo;
import com.hsy.crm.web.domain.vo.order.OrderVo;
import com.hsy.crm.web.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderAction extends BaseAction {

    @Autowired
    OrderService orderService;

    @RequestMapping("/insert")
    public String insert(OrderVo orderVo) {
        return Response.body(orderService.insert(orderVo));
    }

    @RequestMapping("/update")
    public String update(OrderVo orderVo) {
        return Response.body(orderService.update(orderVo));
    }

    @RequestMapping("/delete")
    public String delete(Order order) {
        return Response.body(orderService.delete(order));
    }

    @RequestMapping("/page")
    public String page(OrderPageVo pageVo) {
        return Response.body(orderService.page(pageVo));
    }

    /*@RequestMapping("/examine")
    public String examine(Order order) {
        return Response.body(orderService.examine(order,App.ExamineSource.EXAM));
    }*/

    @RequestMapping("/invalid")
    public String invalid(Order order) {
        return Response.body(orderService.invalid(order));
    }

    @RequestMapping("/getOrder")
    public String getOrder(OrderGetVo orderGetVo) {
        return Response.body(orderService.getOrder(orderGetVo));
    }

    @RequestMapping("/batchPage")
    public String batchPage(BatchPageVo pageVo) {
        return Response.body(orderService.batchPage(pageVo));
    }

    @RequestMapping("/needRefresh")
    public String needRefresh(HttpSession session, Order order) {
        Unified<OrderRefreshPo> unified = new Unified<>();
        int account = getIntSession(session,SecretKey.ACCOUNT);
        int store = getIntSession(session,SecretKey.STORE);
        OrderRefreshPo orderRefreshPo = new OrderRefreshPo(account,store);
        unified.setData(orderRefreshPo);
        return Response.body(unified);
    }

}
